package com.pactera.asmp.server.common.websocket.config;

import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import org.springframework.web.util.WebAppRootListener;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

/**
 * @ProjectName: tlsserver
 * @Package com.pactera.asmp.server.common.websocket.config
 * @ClassName: WebSocketConfig
 * @Description: WS统一配置类
 * @Date 2020/06/18 18:06
 * @Author lvzhiqiang
 * @Version 1.0
 */
@Configuration
public class WebSocketConfig  implements ServletContextInitializer {

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    //配置websocket传输大小，50M
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        servletContext.addListener(WebAppRootListener.class);
        /*
        servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize","52428800");
        servletContext.setInitParameter("org.apache.tomcat.websocket.binaryBufferSize","52428800");
        */
        servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize","24428800");
        servletContext.setInitParameter("org.apache.tomcat.websocket.binaryBufferSize","24428800");

    }
}
